package cn.dgut.training.advice;

import cn.dgut.training.exception.UnLoginException;
import cn.dgut.training.vo.CommonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestControllerAdvice
public class ExceptionControllerAdvice {

    //@ExceptionHandler(value = Exception.class)
    public CommonResponse<String> handlerShopException(HttpServletRequest request,Exception e){

        CommonResponse commonResponse=CommonResponse.fail();
        String messagee=e.getMessage();
        commonResponse.setData(messagee);
        log.error(messagee);
        return  commonResponse;
    }

    @ExceptionHandler(value = UnLoginException.class)
    public CommonResponse<String> unLoginException(){

        return  CommonResponse.unLogin();
    }

}
